home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / MiscKit1.7.1 / MiscKit / Palettes / MiscTeePalette / MiscDistInspector.m < prev    next >
Encoding:
Text File  |  1994-10-24  |  3.6 KB  |  144 lines

  1. //
  2. //    MiscDistInspector.m -- Inspector object for MiscDistributor.
  3. //
  4. //        Written by Don Yacktman.  Copyright 1994 by Don Yacktman.
  5. //                Version 1.0  All rights reserved.
  6. //
  7. //        This notice may not be removed from this source code.
  8. //
  9. //    This object is included in the MiscKit by permission from the author
  10. //    and its use is governed by the MiscKit license, found in the file
  11. //    "LICENSE.rtf" in the MiscKit distribution.  Please refer to that file
  12. //    for a list of all applicable permissions and restrictions.
  13. //    
  14.  
  15. #import "MiscDistInspector.h"
  16. #import "MiscDistributorPrivate.h"
  17. #import "_MiscDistributorConnection.h"
  18.  
  19. @implementation MiscDistributor(IBSupport)
  20.  
  21. - (const char *)getInspectorClassName
  22. {
  23.     return "MiscDistributorInspector";
  24. }
  25.  
  26. - (NXImage *)getIBImage
  27. {
  28.     id    idBundle;
  29.     id    idImage;
  30.     char buf[MAXPATHLEN + 1];
  31.     
  32.     idBundle = [NXBundle bundleForClass:[MiscDistributorInspector class]];
  33.     [idBundle getPath:buf forResource:"MiscDistributor" ofType:"tiff"];
  34.     idImage = [[NXImage alloc] initFromFile:buf];
  35.     
  36.     return idImage;
  37. }
  38.  
  39. @end
  40.  
  41. @implementation MiscDistributorInspector
  42.  
  43. - init
  44. {    
  45.     char buf[MAXPATHLEN + 1];
  46.     id bundle;
  47.     [super init];
  48.     bundle = [NXBundle bundleForClass:[MiscDistributor class]];
  49.     [bundle getPath:buf forResource:"MiscDistributorInspector" ofType:"nib"];
  50.     [NXApp loadNibFile:buf owner:self withNames:NO fromZone:[self zone]];
  51.     return self;
  52. }
  53.  
  54. - (BOOL)wantsButtons { return NO; }
  55.  
  56. - revert:sender
  57. {
  58.     connections = [object _connectionList];
  59.     [self setUpMatrix];
  60.     [self selectRow:0 notify:YES];
  61.     return [super revert:sender];
  62. }
  63.  
  64. - ok:sender
  65. {
  66.     return [super ok:sender];
  67. }
  68.  
  69. - setUpMatrix
  70. {
  71.     int i;
  72.     // populate matrix with connections' names
  73.     [connectionMatrix renewRows:[connections count] cols:1];
  74.     for (i=0; i<[connections count]; i++) {
  75.         [[connectionMatrix cellAt:i :0]
  76.                 setTitle:[[connections objectAt:i] connectionName]];
  77.     }
  78.     [connectionMatrix sizeToCells];
  79.     [connectionMatrix display];
  80.     return self;
  81. }
  82.  
  83. - editName
  84. {
  85.     [window makeFirstResponder:connectionNameText];
  86.     [connectionNameText selectText:self];
  87.     return self;
  88. }
  89.  
  90. - selectRow:(int)i notify:(BOOL)flag
  91. {
  92.     [connectionMatrix selectCellAt:i :0];
  93.     [self selectionChanged:connectionMatrix];
  94.     [connectionMatrix display];
  95.     [self editName];
  96.     return self;
  97. }
  98.  
  99. - selectionChanged:sender
  100. {
  101.     // change values of name/dir widgets to reflect selected connection
  102.     selObject = [connections objectAt:[connectionMatrix selectedRow]];
  103.     [connectionNameText setStringValue:[selObject connectionName]];
  104.     if ([selObject direction] == MiscIn) {
  105.         [connectionDirMatrix selectCellAt:0 :0];
  106.     } else if ([selObject direction] == MiscOut) {
  107.         [connectionDirMatrix selectCellAt:0 :1];
  108.     } else if ([selObject direction] == MiscInout) {
  109.         [connectionDirMatrix selectCellAt:0 :2];
  110.     }
  111.     [self editName];
  112.     return self;
  113. }
  114.  
  115. - addConnection:sender
  116. {
  117.     id newConnection = [[_MiscDistributorConnection alloc] init];
  118.     // add a connection to the list and matrix, and select it in the matrix
  119.     [connections addObject:newConnection];
  120.     [newConnection setConnectionName:"UNTITLED"];
  121.     [newConnection setDirection:MiscInout];
  122.     [self setUpMatrix];
  123.     [self selectRow:([connections count] - 1) notify:YES];
  124.     return self;
  125. }
  126.  
  127. - changeConnection:sender
  128. {
  129.     int theRow = [connectionMatrix selectedRow];
  130.     // take values of name/dir widgets and change selected connection
  131.     switch ([connectionDirMatrix selectedCol]) {
  132.         case 0 : [selObject setDirection:MiscIn]; break;
  133.         case 1 : [selObject setDirection:MiscOut]; break;
  134.         case 2 : [selObject setDirection:MiscInout]; break;
  135.         default: [selObject setDirection:MiscIn]; break;
  136.     }
  137.     [selObject setConnectionName:[connectionNameText stringValue]];
  138.     [self setUpMatrix];
  139.     [self selectRow:theRow notify:NO];
  140.     return self;
  141. }
  142.  
  143. @end
  144.